#include <stdio.h>
#include "Request.h"

CRequest::CRequest(void)
{
}

CRequest::~CRequest(void)
{
}

 
int CRequest::get_cert_request(char *pszCommonName, char *pszSeriName, char *pszPublickey, char *pszRequest)
{
	char *req = "<requestinfo><reqtype>2113</reqtype><baseinfo><comname>%s</comname>\
<email>lmca@longmai.com</email><orgunit>development</orgunit><org>longmai</org>\
<city>Beijing</city><province>Beijing</province><couctry>CN</couctry><subjectname>lm</subjectname>\
<altsubjectnamelist><altsubjectname><type>1</type><value>longmai@longmai.com.cn</value></altsubjectname>\
</altsubjectnamelist></baseinfo><attrlist><attr></attr></attrlist><enccert><enccertsn>%s</enccertsn>\
<enckeyusage>keyEncipherment,dataEncipherment,keyAgreement</enckeyusage><encextkeyusage>clientAuth,1.3.6.1.4.1.311.20.2.2</encextkeyusage>\
<encpublickey>MIGJAoGBANJWP+22WmUowO981kYvwiHj8DIotgOFI21TPZlt8/Ser1i382IImMPXMqyW6kJyifl9xX6cJnI1KyLj8gev3td+jF4Qo4IE/6DUntNE29qfr5aA+oWw1JJC/+YJ7v3tDXrqwHNRCCVkgZhe7XJ5opCaLrucjeNEMvmVW0brO3BlAgMBAAE=</encpublickey>\
<encprivatekey>buJfu/YI+YJocffUrDCCj6r9YNZpfrwYtyPffi/gU4/3B7eaowRPV144rRBSLdhnRbyBNXqVQgYeqobwxj5IAbajQeqkdgEzhpfy5ntlTwFKa8dDycF6/xpRsYiN0B4P/jqTn9glXWT8UCmazO72HHnXELaR650RQM77HCpIPg59hOjzT6a8HajzqoG5KhLrmo9Ta+UsAjfbp4OWGzepsmj8l9U85Posu8vRgM8CqvmieZ79FstI8TR7XZzlTWVi5+hZz8Ogk6rVOhqEfyB/dtILTQTMY40EOyHPjVwNV7CGAxxaYk7ZBmGVU9RByQXWb4eQ510UwhDeA+rBWhM9lMz3nL5OWE4wkM52YADOK8d8W6YPYAYkO2GM5PZcMpbRvtyW9n+d23i9UIu1Ogb13rNV95l3k1URBpLiFKHUn8LhIpEnrKggqA8YrvRPWFJDF8HYOG3wFzczJxFUg2WWsE2U9go2mO3hLnG6i9ZFgZ+iuq40wJ9eovNWwmEDEXNpBAsqD0KeVeFA2zrNARV8C8okuyoS3ERo5695oVtgn/rkT8DdbHwEYPsFxa2uVEqu8JH9LK63Q/2gbn0rB4iqUrD875P56u/jZ53mszwmvaZMTHMORcD6tedsWe0VtF5Hn4yoX4WOrM1ujv0Wo4guN6wne93LdMz7GPEtBRCYLKAbFtoz+TgV4I6uGCvxR95tpWcHisxtVpK4SgudS0hRTcfGpruPQCPnKNc9GCyi4H4cs3f66e/9vIrCrPdoAJMpj4T3o1djSN0ACGR2UELM+H4074kZ8cun5qUeIS44nEQ=</encprivatekey>\
<enckeypwd>Hwhy+BO5UmOudORXuKja93REiiNGYUphtpkDhuaXAi1hDvt16UdVlXkMv4qI5rX54VxGPhrNertRG6x\
K73TuF3oROv2utYtrpJ2odrTzH+pIzbKrFPJ/qgN+4AhFl5LGmNZsulcLjoVFFTbSR7fvwzGxuN9B61pTxGvUQP16vCQ=</enckeypwd>\
</enccert><signcert><signcertsn>1%s</signcertsn><signkeyusage>digitalSignature</signkeyusage><signextkeyusage>\
clientAuth,1.3.6.1.4.1.311.20.2.2</signextkeyusage>\
<signpublickey>%s</signpublickey>\
</signcert><notbefore>20150917120000</notbefore><notafter>20350917120000</notafter>\
<signkeynum>3</signkeynum>\
<rootcert>MIIDNjCCAp+gAwIBAgIBATANBgkqhkiG9w0BAQUFADCBpzEqMCgGA1UEAwwhTE0gUlNBIFJvb3QgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MSAwHgYJKoZIhvcNAQkBDBFsbUBsb25nbWFpLmNvbS5jbjEUMBIGA1UECwwLZGV2ZWxvcG1lbnQxEDAOBgNVBAoMB2xvbmdtYWkxEDAOBgNVBAcMB0JlaWppbmcxEDAOBgNVBAgMB0JlaWppbmcxCzAJBgNVBAYMAkNOMB4XDTE1MDkxNzA0MDAwMFoXDTM1MDkxNzA0MDAwMFowgacxKjAoBg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IyYLUqD/S23E0dPgwBqpTeHCyZRLllOhhlTIbAgWtOvl/xyyiEvruiSWo54RubkG5c3heDKhuV8IWDPuD2NOt9GsTOJZoDBVN8aL9kqupkxMLH91J4O54BimkJGx9r355J+dv4UPa0CYozIohjBRqRrG4QxLF+3lpyhykVNX2HuF6me1/1QTVhKsG+rzob4x4NkpZZAn6WO0Pp7YJqzSIdJCubjPZ7AN08I1SpqrvkTikYBS40C4pN2a8sVnk1fzow6YK3BKOHaIltIzQzEgxqVgr1DEo+jZj2eMJcG0HoClyOP+BNTZRn+aPYUlnf8MsakkoSNLG22/OolRfc3ULkR/yId/gRt9vWPzgEUmpnFzGfpb0EsmuPQd8x31rq0VUZwJjuW+fzhB0kJ29D1/IzJg5T4Rk916GVvDUQ+mPzuZPK7VySrw86wHly83iUo3lwimaDYci5wuS4i26Gx4CEP9p1d/HTMCL4inDdZh465Q+5Qs7EIK9sSwBxLp8sTHvNxFI8S</rootprivatekey>\
<rootkeypwd>2MvOqZS+oL2fW42O3EsgRw==</rootkeypwd>\
<crldispoint>http://192.168.0.8/lmcams/</crldispoint></requestinfo>";

	sprintf(pszRequest, req, pszCommonName, pszSeriName, pszSeriName, pszPublickey);
	return 1;
}


int CRequest::get_cert_request_ecc(char *pszCommonName, char *pszSeriName, char *pszPublickey, char *pszRequest)
{
	char *req = "<requestinfo><reqtype>2103</reqtype><baseinfo><comname>%s</comname>\
<email>lmca@longmai.com</email><orgunit>development</orgunit><org>longmai</org>\
<city>Beijing</city><province>Beijing</province><couctry>CN</couctry>\
<subjectname>suhl</subjectname><altsubjectnamelist><altsubjectname><type>1</type>\
<value>longmai@longmai.com.cn</value></altsubjectname></altsubjectnamelist></baseinfo>\
<attrlist><attr></attr></attrlist><enccert><enccertsn>%s</enccertsn>\
<enckeyusage>keyEncipherment,dataEncipherment,keyAgreement</enckeyusage><encextkeyusage>\
clientAuth,1.3.6.1.4.1.311.20.2.2</encextkeyusage><encpublickey>AAEAAGVJsuGNsJA5cKwq60d+GT/+KTIl/GOXtGX\
b4SUvtcj3jmh0lcbDUl04hxIdvfMVz3oxrZf1mq5ymIPyTlllmWc=</encpublickey><en\
cprivatekey>n1apIU92hxXrHp3Qbxr0Gp3qOlkMOWS4rbtMRB6K/+E=</encprivatekey>\
<enckeypwd>cVel6acLs5LxPMkl1+4t26wMAQZ+YpgFhXrmhl6aAjGSYqJoh3rY2y8fZRYLPI3\
YtCiwAbVmbyjvy0QxBSvy0B1e8FBWN/7jzLeIx6sv9yCa657t2DaoIkXfpYpRjkYNXOeU4i2c7\
X8ASyZixEnvRw==</enckeypwd></enccert><signcert><signcertsn>1%s</signcertsn>\
<signkeyusage>digitalSignature</signkeyusage><signextkeyusage>clientAuth,1.3.6.1.4.1.311.20.2.2</signextkeyusage>\
<signpublickey>%s</signpublickey></signcert><notbefore>20150917120000</notbefore>\
<notafter>20350917120000</notafter><signkeynum>3</signkeynum>\
<rootcert>MIIChDCCAi+gAwIBAgIBATAMBggqgRzPVQGDdQUAMIGfMSowKAYDVQQDDCFMTSBTTTIgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxIDAeBgkqhkiG9w0BCQEMEWxtQGxvbmdtYWkuY29tLmNuMQwwCgYDVQQLDANKSVQxEDAOBgNVBAoMB2xvbmdtYWkxEDAOBgNVBAcMB0JlaWppbmcxEDAOBgNVBAgMB0JlaWppbmcxCzAJBgNVBAYMAkNOMB4XDTE1MDkxNzA0MDAwMFoXDTM1MDkxNzA0MDAwMFowgZ8xKjAoBgNVBAMMIUxNIFNNMiBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eTEgMB4GCSqGSIb3DQEJAQwRbG1AbG9uZ21haS5jb20uY24xDDAKBgNVBAsMA0pJVDEQMA4GA1UECgwHbG9uZ21haTEQMA4GA1UEBwwHQmVpamluZzEQMA4GA1UECAwHQmVpamluZzELMAkGA1UEBgwCQ04wUjAMBggqgRzPVQGDdQUAA0IABNSYxIYaJYeeGpUAXoYCdXT5m6UteB5imgosEwc8bpwFBIUKOMBXzQfcn5tPeXfH/fdVd8jKvFQVkFbrL34h1rmjXzBdMAsGA1UdDwQEAwIHgDAhBgNVHREEGjAYgRZsb25nbWFpQGxvbmdtYWkuY29tLmNuMCsGA1UdHwQkMCIwIKAeoByGGmh0dHA6Ly8xMjcuMC4wLjEvdGVzdGNhbXMvMAwGCCqBHM9VAYN1BQADQQDMi2XEQhrgcDK7yIulU4rBM7mEp+a/N1EypvjA0/ZGoW4M80+OnDqCHFEhVwVtX/SMCJ6YHPvnNiQF7Lt/tCGs</rootcert>\
<rootprivatekey>mCW2uczIj6iK+yxcSFTdeWoZiQupnA5yr4th0pizVYc=</rootprivatekey><rootkeypwd>ciRf\
YwhXcg4wcGcoTVEkGA==</rootkeypwd><crldispoint>http://192.168.0.8/testcams/</crldispoint>\
</requestinfo>";


	sprintf(pszRequest, req, pszCommonName, pszSeriName, pszSeriName, pszPublickey);
	return 1;
}

int CRequest::analyse_response(char *pszResponse, char *pszKeypair, char *pszSignCert, char *pszEncCert)
{

	return 1;
}